package com.sgcc.ln.pmos.e_ln_personalcenter.activity;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.ln.pmos.arouter.mall.MallArouterPath;
import com.sgcc.ln.pmos.arouter.personalcenter.PersonalCenterArouterPath;
import com.sgcc.ln.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.ln.pmos.common.bean.PackageBean;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.e_ln_personalcenter.adapter.FocusAdapter;
import com.sgcc.ln.pmos.e_ln_personalcenter.bean.CollectionBean;
import com.sgcc.ln.pmos.e_ln_personalcenter.contract.FocusContract;
import com.sgcc.ln.pmos.e_ln_personalcenter.presenter.FocusPresenter;

/**
 * 关注列表
 */
@Route(path = PersonalCenterArouterPath.PERSONALCENTER_FOCUS)
public class FocusActivity extends MvpBaseRecycleActivity<PackageBean, FocusPresenter> implements FocusContract.View {

    private FocusAdapter mFocusAdapter;

    @Override
    public String getTitleText() {
        return "我的关注";
    }

    @Override
    public void querySuccess(CollectionBean response) {
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getRows() != null) {
                    loadSuccess(false, response.getRows());
                }
            } else {

                loadFalied();
            }
        }
    }

    @Override
    protected void initViews() {
        super.initViews();
        title_bar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });
    }

    @Override
    public void queryFailed() {
        loadFalied();
    }

    @Override
    protected FocusPresenter createPresenter() {
        return new FocusPresenter();
    }


    @Override
    public BaseQuickAdapter getAdapter() {
        mFocusAdapter = new FocusAdapter(mContext);
        mFocusAdapter.setOnItemClickListener(new FocusAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, PackageBean bean) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_STOREHOMEPAGE)
                        .withString("membersSdId", bean.getMembersSdId())
                        .navigation();
            }
        });
        return mFocusAdapter;
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mPresenter.getFocusList(listSize, isloading);
    }
}
